package com.mock.action.organisation.supportingmaterial;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.mock.dao.SupportingMaterialDao;
import com.mock.dao.SupportingMaterialTypeDao;
import com.mock.dao.UserDao;
import com.mock.dao.impl.OrganisationDaoImpl;
import com.mock.dao.impl.SupportingMaterialDaoImpl;
import com.mock.dao.impl.SupportingMaterialTypeDaoImpl;
import com.mock.dao.impl.UserDaoImpl;
import com.mock.model.SupportingMaterial;
import com.mock.model.SupportingMaterialType;
import com.mock.model.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class AddSupportingMaterialAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public String execute() throws Exception {
		Map<String, Object> session = ActionContext.getContext().getSession();
		Long userId = (Long) session.get("userId");
		user = userDao.getById(userId);		
		generateData();
		return SUCCESS;
	}
	
	public String create() throws Exception {		
		Map<String, Object> session = ActionContext.getContext().getSession();
		Long userId = (Long) session.get("userId");
		SupportingMaterial supportingMaterial = new SupportingMaterial();
		supportingMaterial.setOrganisation(new OrganisationDaoImpl().getById(organisationId));
		supportingMaterial.setUrl(url);
		supportingMaterial.setDescription(description);
		supportingMaterial.setSupportingMaterialType(supportingMaterialTypeDao.getById(supportingMaterialType));
		supportingMaterial.setUser(userDao.getById(userId));
		supportingMaterial.setAddedDate(today);
		supportingMaterialDao.add(supportingMaterial);
		return SUCCESS;
	}
	
	public void generateData() {		
		supportingMaterialTypes = supportingMaterialTypeDao.getAllSupportingMaterialTypes();
	}
	
	private long organisationId = -1L;
	
	private List<SupportingMaterialType> supportingMaterialTypes = new ArrayList<SupportingMaterialType>();
	private SupportingMaterialTypeDao supportingMaterialTypeDao = new SupportingMaterialTypeDaoImpl();
	private SupportingMaterialDao supportingMaterialDao = new SupportingMaterialDaoImpl();
	private UserDao userDao = new UserDaoImpl();
	
	private String url;
	private String description;
	private Long supportingMaterialType;
	private String addedBy;
	private Date addedDate;
	
	private User user;
	private Date today = new Date();

	public long getOrganisationId() {
		return organisationId;
	}

	public void setOrganisationId(long organisationId) {
		this.organisationId = organisationId;
	}

	public List<SupportingMaterialType> getSupportingMaterialTypes() {
		return supportingMaterialTypes;
	}

	public void setSupportingMaterialTypes(
			List<SupportingMaterialType> supportingMaterialTypes) {
		this.supportingMaterialTypes = supportingMaterialTypes;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Long getSupportingMaterialType() {
		return supportingMaterialType;
	}

	public void setSupportingMaterialType(Long supportingMaterialType) {
		this.supportingMaterialType = supportingMaterialType;
	}

	public String getAddedBy() {
		return addedBy;
	}

	public void setAddedBy(String addedBy) {
		this.addedBy = addedBy;
	}

	public Date getAddedDate() {
		return addedDate;
	}

	public void setAddedDate(Date addedDate) {
		this.addedDate = addedDate;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Date getToday() {
		return today;
	}

	public void setToday(Date today) {
		this.today = today;
	}
	
}
